// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-6-17

#include "stdafx.h"
#include "mainborder.h"
#include "mainwnd.h"

IMPLEMENT_DYNAMIC(CJoyMainBorder, CJoyWnd)

//##ModelId=44C4B5E101FA
CJoyMainBorder::CJoyMainBorder(void)
{
    m_hitTest   = HTTRANSPARENT;
}

//##ModelId=44C4B5E10203
CJoyMainBorder::~CJoyMainBorder(void)
{
}

//##ModelId=44C4B5E10205
bool CJoyMainBorder::Create(CJoyWnd* mainWnd, const CRect& area, AlignType align)
{

    DWORD dwStyle = WS_CHILD | WS_CLIPCHILDREN;
    if(m_visible)
    {
        dwStyle |= WS_VISIBLE;
    }
    if(!CreateEx(
        0,
        JoyGetManager()->GetWndClass(),
        NULL,
        dwStyle,
        area,
        mainWnd,
        0))
    {
        return false;
    }

    SetAlign(align);
    return true;
}

BEGIN_MESSAGE_MAP(CJoyMainBorder, CJoyWnd)
    ON_WM_NCHITTEST()
END_MESSAGE_MAP()

//##ModelId=44C4B5E101F4
void CJoyMainBorder::CM_LoadSkin(CJoyXmlElement* pSkinElem)
{
    __super::CM_LoadSkin(pSkinElem);

    CJoyXmlAttribute* pBrushAttrib = pSkinElem->FindAttribute("brush");
    if(pBrushAttrib != NULL)
    {
        if(!pBrushAttrib->m_value.IsEmpty())
        {
            m_backImage = JoyGetManager()->CreateImage(pBrushAttrib->m_value);
        }
    }
}

//##ModelId=44C4B5E101F7
void CJoyMainBorder::CM_Draw(Graphics& graph)
{
    if(m_backImage == NULL)
    {
        return;
    }

    TextureBrush backBrush(m_backImage, WrapModeTile);

    graph.FillRectangle(&backBrush, Rect(0, 0, m_area.Width(), m_area.Height()));
}

//##ModelId=44C4B5E10209
UINT CJoyMainBorder::OnNcHitTest(CPoint point)
{
    //CPoint p(point);
    //ScreenToClient(&p);
    //LRESULT r = DoHitTest(p);
    //if(r == 0)
    //{
    //    return (UINT)HTTRANSPARENT;
    //}
    //return (UINT)r;
    return __super::OnNcHitTest(point);
}
